﻿namespace HRM.CORE.REPORT
{
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraReports.UI;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using Common.Report;
    using HRM.CORE;
    using Extra;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms; using Common;

    public class xucOptionPrintSalary : Common.xucBaseOptionPrint
    {
        private IContainer components;
        private DateEdit dtDate;
        private GroupBox groupBox1;
        private LabelControl labelControl1;
        private LabelControl labelControl4;
        private string m_Code;
        private string m_EmployeeCode;
        private int m_Level;
        private int m_Month;
        private int m_Year;
        private RadioGroup radioGroup1;
        private SimpleButton simpleButton1;
        private xucOrganizationEdit xucOrganizationEdit1;

        public xucOptionPrintSalary()
        {
            this.m_Level = 0;
            this.m_Code = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
        }

        public xucOptionPrintSalary(int Level, string Code)
        {
            this.m_Level = 0;
            this.m_Code = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
            this.m_Level = Level;
            this.m_Code = Code;
            this.xucOrganizationEdit1.LoadData(this.m_Level, this.m_Code);
            this.m_Year = System.DateTime.Now.Year;
            this.m_Month = System.DateTime.Now.Month;
            this.dtDate.DateTime = System.DateTime.Now;
        }

        public xucOptionPrintSalary(int Level, string Code, int Month, int Year, string EmployeeCode)
        {
            this.m_Level = 0;
            this.m_Code = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
            this.m_Level = Level;
            this.m_Code = Code;
            this.xucOrganizationEdit1.LoadData(this.m_Level, this.m_Code);
            this.m_EmployeeCode = EmployeeCode;
            System.DateTime time = new System.DateTime(this.m_Year = Year, this.m_Month = Month, 1);
            this.dtDate.DateTime = time;
        }

        protected override void Cancel()
        {
            base.ParentForm.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void dtDate_EditValueChanged(object sender, EventArgs e)
        {
            this.m_Month = this.dtDate.DateTime.Month;
            this.m_Year = this.dtDate.DateTime.Year;
        }

        private void InitializeComponent()
        {
            MenuButton button = new MenuButton();
            ItemCommand command = new ItemCommand();
            ItemCommand command2 = new ItemCommand();
            ItemCommand command3 = new ItemCommand();
            ItemCommand command4 = new ItemCommand();
            ItemCommand command5 = new ItemCommand();
            ItemCommand command6 = new ItemCommand();
            ItemCommand command7 = new ItemCommand();
            ItemCommand command8 = new ItemCommand();
            ItemCommand command9 = new ItemCommand();
            ItemCommand command10 = new ItemCommand();
            ItemCommand command11 = new ItemCommand();
            ItemCommand command12 = new ItemCommand();
            ItemCommand command13 = new ItemCommand();
            ItemCommand command14 = new ItemCommand();
            ItemCommand command15 = new ItemCommand();
            ItemCommand command16 = new ItemCommand();
            ItemCommand command17 = new ItemCommand();
            ItemCommand command18 = new ItemCommand();
            ItemCommand command19 = new ItemCommand();
            ItemCommand command20 = new ItemCommand();
            ItemCommand command21 = new ItemCommand();
            ItemCommand command22 = new ItemCommand();
            ItemCommand command23 = new ItemCommand();
            ItemCommand command24 = new ItemCommand();
            ItemCommand command25 = new ItemCommand();
            ItemCommand command26 = new ItemCommand();
            ItemCommand command27 = new ItemCommand();
            ItemCommand command28 = new ItemCommand();
            ItemCommand command29 = new ItemCommand();
            this.groupBox1 = new GroupBox();
            this.radioGroup1 = new RadioGroup();
            this.labelControl4 = new LabelControl();
            this.labelControl1 = new LabelControl();
            this.dtDate = new DateEdit();
            this.simpleButton1 = new SimpleButton();
            this.xucOrganizationEdit1 = new xucOrganizationEdit();
            this.groupBox1.SuspendLayout();
            this.radioGroup1.Properties.BeginInit();
            this.dtDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDate.Properties.BeginInit();
            base.SuspendLayout();
            base.btnPrintPreview.Location = new Point(0x1aa, 0xd6);
            base.btnPrint.Location = new Point(0x157, 0xd6);
            base.btnCancel.Location = new Point(0xfd, 0xd6);
            this.groupBox1.Controls.Add(this.radioGroup1);
            this.groupBox1.Controls.Add(this.labelControl4);
            this.groupBox1.Controls.Add(this.xucOrganizationEdit1);
            this.groupBox1.Controls.Add(this.labelControl1);
            this.groupBox1.Controls.Add(this.dtDate);
            this.groupBox1.Location = new Point(12, 4);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x1f9, 0xc5);
            this.groupBox1.TabIndex = 0x26;
            this.groupBox1.TabStop = false;
            this.radioGroup1.Location = new Point(14, 0x4f);
            this.radioGroup1.Name = "radioGroup1";
            this.radioGroup1.Properties.Appearance.BackColor = Color.Transparent;
            this.radioGroup1.Properties.Appearance.Options.UseBackColor = true;
            this.radioGroup1.Properties.BorderStyle = BorderStyles.NoBorder;
            this.radioGroup1.Properties.Items.AddRange(new RadioGroupItem[] { new RadioGroupItem(null, "In bảng lương cho tất cả nh\x00e2n vi\x00ean theo ph\x00f2ng ban được chọn"), new RadioGroupItem(null, "In bảng lương tăng ca cho tất cả nh\x00e2n vi\x00ean theo ph\x00f2ng ban được chọn"), new RadioGroupItem(null, "In phiếu lương cho tất cả nh\x00e2n vi\x00ean theo ph\x00f2ng ban được chọn") });
            this.radioGroup1.Size = new Size(0x18a, 0x70);
            this.radioGroup1.TabIndex = 40;
            this.labelControl4.Location = new Point(14, 0x12);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x3d, 13);
            this.labelControl4.TabIndex = 0x27;
            this.labelControl4.Text = "Chọn đơn vị:";
            this.labelControl1.Location = new Point(14, 50);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(60, 13);
            this.labelControl1.TabIndex = 13;
            this.labelControl1.Text = "Chọn th\x00e1ng:";
            this.dtDate.EditValue = null;
            this.dtDate.Location = new Point(0x51, 0x30);
            this.dtDate.Name = "dtDate";
            this.dtDate.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.dtDate.Properties.Appearance.Options.UseFont = true;
            this.dtDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate.Properties.DisplayFormat.FormatString = "MM/yyyy";
            this.dtDate.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtDate.Properties.EditFormat.FormatString = "MM/yyyy";
            this.dtDate.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtDate.Properties.Mask.EditMask = "MM/yyyy";
            this.dtDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate.Size = new Size(110, 20);
            this.dtDate.TabIndex = 12;
            this.dtDate.EditValueChanged += new EventHandler(this.dtDate_EditValueChanged);
            this.simpleButton1.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.simpleButton1.Location = new Point(12, 0xd6);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new Size(0x54, 0x1b);
            this.simpleButton1.TabIndex = 0x27;
            this.simpleButton1.Text = "T\x00f9y chọn";
            this.simpleButton1.Visible = false;
            this.simpleButton1.Click += new EventHandler(this.simpleButton1_Click);
            this.xucOrganizationEdit1.BranchCode = null;
            this.xucOrganizationEdit1.Code = null;
            this.xucOrganizationEdit1.DepartmentCode = null;
            this.xucOrganizationEdit1.EmployeeCode = null;
            this.xucOrganizationEdit1.GroupCode = null;
            this.xucOrganizationEdit1.IsClose = CloseOrNew.None;
            this.xucOrganizationEdit1.Level = 0;
            this.xucOrganizationEdit1.Location = new Point(0x51, 0x10);
            this.xucOrganizationEdit1.Name = "xucOrganizationEdit1";
            this.xucOrganizationEdit1.NotSave = false;
            command.Caption = "";
            command.Enable = false;
            command.Visibility = BarItemVisibility.Never;
            button.Add = command;
            command2.Caption = "";
            command2.Enable = false;
            command2.Visibility = BarItemVisibility.Never;
            button.Cancel = command2;
            command3.Caption = "";
            command3.Enable = false;
            command3.Visibility = BarItemVisibility.Never;
            button.Change = command3;
            command4.Caption = "";
            command4.Enable = false;
            command4.Visibility = BarItemVisibility.Never;
            button.Close = command4;
            command5.Caption = "";
            command5.Enable = false;
            command5.Visibility = BarItemVisibility.Never;
            button.Custom = command5;
            command6.Caption = "";
            command6.Enable = false;
            command6.Visibility = BarItemVisibility.Never;
            button.Delete = command6;
            command7.Caption = "";
            command7.Enable = false;
            command7.Visibility = BarItemVisibility.Never;
            button.Export = command7;
            command8.Caption = "";
            command8.Enable = false;
            command8.Visibility = BarItemVisibility.Never;
            button.Filter = command8;
            command9.Caption = "";
            command9.Enable = false;
            command9.Visibility = BarItemVisibility.Never;
            button.FilterCustomer = command9;
            command10.Caption = "";
            command10.Enable = false;
            command10.Visibility = BarItemVisibility.Never;
            button.FilterStock = command10;
            command11.Caption = "";
            command11.Enable = false;
            command11.Visibility = BarItemVisibility.Never;
            button.Find = command11;
            button.GClose = false;
            button.GCommand = false;
            button.GExport = false;
            command12.Caption = "";
            command12.Enable = false;
            command12.Visibility = BarItemVisibility.Never;
            button.Go = command12;
            button.GOption = false;
            button.GPrint = false;
            button.GRecords = false;
            button.GSearchBar = false;
            button.GSettings = false;
            button.GVaildation = false;
            command13.Caption = "";
            command13.Enable = false;
            command13.Visibility = BarItemVisibility.Never;
            button.Import = command13;
            command14.Caption = "";
            command14.Enable = false;
            command14.Visibility = BarItemVisibility.Never;
            button.Next = command14;
            command15.Caption = "";
            command15.Enable = false;
            command15.Visibility = BarItemVisibility.Never;
            button.PageSetup = command15;
            button.PHome = false;
            command16.Caption = "";
            command16.Enable = false;
            command16.Visibility = BarItemVisibility.Never;
            button.Previous = command16;
            command17.Caption = "";
            command17.Enable = false;
            command17.Visibility = BarItemVisibility.Never;
            button.Print = command17;
            command18.Caption = "";
            command18.Enable = false;
            command18.Visibility = BarItemVisibility.Never;
            button.PrintPreview = command18;
            button.PTool = false;
            command19.Caption = "";
            command19.Enable = false;
            command19.Visibility = BarItemVisibility.Never;
            button.Redo = command19;
            command20.Caption = "";
            command20.Enable = false;
            command20.Visibility = BarItemVisibility.Never;
            button.Refresh = command20;
            command21.Caption = "";
            command21.Enable = false;
            command21.Visibility = BarItemVisibility.Never;
            button.Save = command21;
            command22.Caption = "";
            command22.Enable = false;
            command22.Visibility = BarItemVisibility.Never;
            button.SaveAndClose = command22;
            command23.Caption = "";
            command23.Enable = false;
            command23.Visibility = BarItemVisibility.Never;
            button.SaveAndNew = command23;
            command24.Caption = "";
            command24.Enable = false;
            command24.Visibility = BarItemVisibility.Never;
            button.Search = command24;
            command25.Caption = "";
            command25.Enable = false;
            command25.Visibility = BarItemVisibility.Never;
            button.SearchText = command25;
            command26.Caption = "";
            command26.Enable = false;
            command26.Visibility = BarItemVisibility.Never;
            button.Task = command26;
            command27.Caption = "";
            command27.Enable = false;
            command27.Visibility = BarItemVisibility.Never;
            button.Undo = command27;
            command28.Caption = "";
            command28.Enable = false;
            command28.Visibility = BarItemVisibility.Never;
            button.Vaildate = command28;
            command29.Caption = "";
            command29.Enable = false;
            command29.Visibility = BarItemVisibility.Never;
            button.View = command29;
            this.xucOrganizationEdit1.RibbonBar = button;
            this.xucOrganizationEdit1.Size = new Size(0x199, 0x16);
            this.xucOrganizationEdit1.Status = Actions.None;
            this.xucOrganizationEdit1.TabIndex = 0x26;
            this.xucOrganizationEdit1.Title = "";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.simpleButton1);
            base.Controls.Add(this.groupBox1);
            base.Name = "xucOptionPrintSalary";
            base.Size = new Size(530, 0xfd);
            base.Controls.SetChildIndex(base.btnPrintPreview, 0);
            base.Controls.SetChildIndex(base.btnPrint, 0);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(this.groupBox1, 0);
            base.Controls.SetChildIndex(this.simpleButton1, 0);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.radioGroup1.Properties.EndInit();
            this.dtDate.Properties.VistaTimeProperties.EndInit();
            this.dtDate.Properties.EndInit();
            base.ResumeLayout(false);
        }

        protected override void Print()
        {
            this.Print(false);
        }

        private void Print(bool IsPrintPreview)
        {
            this.m_Level = this.xucOrganizationEdit1.Level;
            this.m_Code = this.xucOrganizationEdit1.Code;
            XtraReport xtraReport = new XtraReport();
            xfmReport report2 = new xfmReport();
            report2.SetTitle("Bảng Chấm C\x00f4ng Th\x00e1ng " + this.m_Month.ToString() + "/" + this.m_Year.ToString());
            HRM_SALARY_TABLELIST hrm_salary_tablelist = new HRM_SALARY_TABLELIST();
            if (!hrm_salary_tablelist.Exist(this.m_Month, this.m_Year))
            {
                XtraMessageBox.Show("Bảng lương th\x00e1ng n\x00e0y kh\x00f4ng tồn tại trong cơ sở dữ liệu của chương tr\x00ecnh!\nVui l\x00f2ng chọn th\x00e1ng b\x00e1o c\x00e1o kh\x00e1c!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                if (this.radioGroup1.SelectedIndex == 0)
                {
                    xtraReport = new rptSalaryTableList(this.m_Level, this.m_Code, this.m_Month, this.m_Year);
                    report2.SetTitle("Bảng Lương Th\x00e1ng " + this.m_Month.ToString() + "/" + this.m_Year.ToString());
                }
                else if (this.radioGroup1.SelectedIndex == 1)
                {
                    xtraReport = new rptSalaryOverTime(this.m_Level, this.m_Code, this.m_Month, this.m_Year);
                    report2.SetTitle("Bảng Lương Tăng Ca Th\x00e1ng " + this.m_Month.ToString() + "/" + this.m_Year.ToString());
                }
                else if (this.radioGroup1.SelectedIndex == 2)
                {
                    xtraReport = new rptSalary2(this.m_Level, this.m_Code, this.m_Month, this.m_Year);
                    report2.SetTitle("Phiếu Lương Th\x00e1ng " + this.m_Month.ToString() + "/" + this.m_Year.ToString());
                }
                if (IsPrintPreview)
                {
                    report2.ShowPrintPreview(xtraReport);
                }
                else
                {
                    PrintDialog dialog = new PrintDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        string printerName = dialog.PrinterSettings.PrinterName;
                        xtraReport.Print(printerName);
                    }
                }
            }
        }

        protected override void PrintPreview()
        {
            this.Print(true);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            new xfmOptionPrintSalaryTableList().ShowDialog();
        }
    }
}

